﻿namespace NEvoWeb.Modules.NB_Store
{
    using DotNetNuke.Entities.Modules;
    using DotNetNuke.Services.Exceptions;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Runtime.CompilerServices;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public class PrintOrder : BaseModule
    {
        [AccessedThroughProperty("PlaceHolder1")]
        private PlaceHolder _PlaceHolder1;
        private int ORID;

        public PrintOrder()
        {
            base.Load += new EventHandler(this.Page_Load);
            this.ORID = -1;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                SettingsController controller2 = new SettingsController();
                OrderController controller = new OrderController();
                NB_Store_OrdersInfo objOrderInfo = null;
                string strSourceText = "";
                if ((this.Request.QueryString["ORID"] != "") && Versioned.IsNumeric(this.Request.QueryString["ORID"].ToString()))
                {
                    NB_Store_SettingsTextInfo info;
                    this.ORID = Conversions.ToInteger(this.Request.QueryString["ORID"]);
                    if (this.Request.QueryString["inv"] != "")
                    {
                        info = controller2.GetSettingsText(this.PortalId, "receiptprint.text", SharedFunctions.GetCurrentCulture());
                    }
                    else
                    {
                        info = controller2.GetSettingsText(this.PortalId, "orderprint.text", SharedFunctions.GetCurrentCulture());
                    }
                    if ((info != null) && (info.SettingText != ""))
                    {
                        strSourceText = info.SettingText;
                        objOrderInfo = controller.GetOrder(this.ORID);
                        if (objOrderInfo != null)
                        {
                            strSourceText = new TokenStoreReplace(objOrderInfo, SharedFunctions.GetCurrentCulture()).DoTokenReplace(strSourceText);
                        }
                    }
                    if ((!SharedFunctions.IsManager(this.PortalId, this.UserInfo) & !SharedFunctions.IsEditor(this.PortalId, this.UserInfo)) && ((this.UserInfo.UserID != objOrderInfo.UserID) | (this.UserInfo.UserID == -1)))
                    {
                        strSourceText = "";
                    }
                    this.PlaceHolder1.Controls.Add(new LiteralControl(this.Server.HtmlDecode(strSourceText)));
                }
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exc = exception1;
                DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException((PortalModuleBase) this, exc);
                ProjectData.ClearProjectError();
            }
        }

        protected virtual PlaceHolder PlaceHolder1
        {
            get
            {
                return this._PlaceHolder1;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._PlaceHolder1 = value;
            }
        }
    }
}

